$(document).ready(function(){
	    // user_list = [{"email": null, "name": "admin", "password": "******", "id": 1, "state": "leaving"}, {"email": null, "name": "root", "password": "******", "id": 2, "state": "leaving"}, {"email": "jure_top@163.com", "name": "jure", "password": "******", "id": 3, "state": "leaving"}, {"email": "jure_top@163.com", "name": "liulong", "password": "******", "id": 4, "state": "leaving"}];

	$("#table_user_list tr:not(:first)").empty();
	for(var key in user_list){
		var item = user_list[key];
		var isCheck = item.state == "active" ? "checked=\"true\"":"";
		$("#table_user_list").append("<tr><td>"+item.id.toString()+"</td><td>"+item.name+"</td></td><td><input type=\"checkbox\" class=\"table_user_list_select\" "+isCheck+"></td></tr>")
	}
	setGloballTableColor();
});
function onSelectAllCheckBox() {
	var checkBox = document.getElementById("table_user_list_select_all");
	if(checkBox.checked){
		$(".table_user_list_select").each(function(i,o){
            // $(o).attr("checked",!$(o).attr("checked"));
            $(this).attr("checked","true"); 
        });
	}
	else{
		$(".table_user_list_select").each(function(i,o){
            $(this).removeAttr("checked"); 
        });
	}
}

function onSetDeviceUsers(){
	var checkBox = $(".table_user_list_select");
	for (var key=0; key< checkBox.length; key++){
		var item = user_list[key]
		if(checkBox[key].checked == true){
			item.state = "active";
		}else{
			item.state = "laving";
		}
		console.log(item)
	}
	json = {"id":getURLString("id"), "user_ids":user_list}
	$.ajax({
		type: "POST",
		url: "/index/get_user_list/",
		// data: JSON.stringify(json),
		// contentType : "application/json",
		// dataType : "json",
		data:"id="+getURLString("id")+"&user_ids="+JSON.stringify(user_list),
		// beforeSend: function(xhr, settings) { if (!(/^(GET|HEAD|OPTIONS|TRACE|POST)$/.test(settings.type)) && !this.crossDomain) xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));},
		success:function () {
			console.log("success");
			self.location=document.referrer;
		}
	});
}
